var gridlist;
var ognid = RequestURLParam.getParam("ognid");
var cate = RequestURLParam.getParam("cate");
$(document).ready(function () {
    gridlist = mini.get('grid');
    gridlist.load({
        'orgDutyPostView.ognId': ognid,
        'orgDutyPostView.postState': '1'
    });
    formData = {
        'sysDuty.orgId': ognid
    };
    ActHttpRequest('SysOrgDuty!list.do', formData, function (data) {
        if (data.OK == "OK") {
            var htmlTxt = "";
            var srcTemIds = "";
            $("#def_ul_myrole").html(htmlTxt);
            for (var i = 0; i < data.List.length; i++) {
                var sysDuty = data.List[i];
                htmlTxt = '<li data_type="' + sysDuty.dutyLevel + '"  id="' + sysDuty.dutyId + '">';
                if ((sysDuty.orgType == 'cate' && sysDuty.orgId != OrgTreeNode.orgId) || (sysDuty.dutyPid != null && sysDuty.dutyPid != "")) {
                    htmlTxt += '<a href="javascript:void(0);" onClick="SelDuty(\'' + sysDuty.dutyId + '\',\'' + sysDuty.dutyName + '\',\'' + sysDuty.orgType + '\');">' + sysDuty.dutyName + '(继承职务)</a></li>';
                } else {
                    htmlTxt += '<a href="javascript:void(0);" onClick="SelDuty(\'' + sysDuty.dutyId + '\',\'' + sysDuty.dutyName + '\');">' + sysDuty.dutyName + '</a></li>';
                }
                $("#def_ul_myrole").append(htmlTxt);
            }
            $("#def_ul_myrole li").each(function () {
                var index = parseInt($(this).attr("data_type"));
                var content = "------";
                for (var i = 0; i < index - 1; i++) {
                    content += "------";
                }
                var before = document.createElement("before");
                $(before).css("color", "#ccc");
                before.innerHTML = content;
                this.insertBefore(before, this.firstChild);
            });
        } else {
            $("#def_ul_myrole").html('<li data_type="1"><a href="javascript:void(0);" style="color:red;" >请添加职务！</a></li>');
        }
    }, null, null, null, '加载中。。。', true);
});

function click_myRole_Sel(id, name) {
    gridlist.load({
        'orgDutyPostView.ognId': ognid,
        'orgDutyPostView.postState': '1',
        'orgDutyPostView.dutyId': id
    });
    $("#grid .mini-panel-title").html('<font color="red">' + name + '</font>(职务)-岗位列表<div style="float:right;display:block;"><a style="margin-left:5px;border:none;background:none;" class="mini-button" hideFocus="" href="javascript:void(0);" onClick="cleatSel()"><span class="mini-button-text  mini-button-icon icon-search">所有岗位</span></a></div>');
}

function cleatSel() {
    $("#grid .mini-panel-title").html('岗位列表');
    gridlist.load({
        'orgDutyPostView.ognId': ognid,
        'orgDutyPostView.postState': '1'
    });
}

function selPost() {
    var rows = gridlist.getSelecteds();
    if (rows || rows.length > 0) {
        var id = [];
        var name = [];
        for (var i = 0; i < rows.length; i++) {
            id.push(rows[i].postId);
            name.push(rows[i].postName);
        }
        window.CloseOwnerWindow({
            'id': id.join(","),
            'name': name.join(",")
        });
    } else {
        mini.alert("请勾选!");
    }
}